package com.jingdun.sport.api.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jingdun.sport.bean.model.ApiResult;
import com.jingdun.sport.bean.model.Withdrawal;
import com.jingdun.sport.service.WithdrawalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;


@RestController
@RequestMapping("/sport/withdrawal/")
@Api(tags = "提现接口")
public class WithdrawalController {

    @Autowired
    private WithdrawalService withdrawalService;

    /**
     * 新增提现接口
     */
    @PostMapping("/addWithdrawal")
    @ApiOperation(value = "新增提现接口", notes = "新增提现接口")
    public ResponseEntity<ApiResult> addWithdrawal(@RequestBody Withdrawal withdrawal) {
        withdrawalService.addWithdrawal(withdrawal);
        ApiResult apiResult = new ApiResult();
        //return ResponseEntity.ok().build();
        return ResponseEntity.ok(apiResult);
    }

    /**
     * 获取提现详情接口
     */
    @GetMapping("/getWithdrawalDetail")
    @ApiOperation(value = "获取提现详情接口", notes = "获取提现详情接口")
    public ApiResult getWithdrawalDetail(long id){
        Map m = new HashMap<String, Object>();
        m.put("id", id);
        Withdrawal withdrawal = withdrawalService.getWithdrawalDetail(m);
        ApiResult apiResult = new ApiResult();
        apiResult.setData(withdrawal);
        return apiResult;
    }

    /**
     * 删除提现接口
     */
    @PostMapping("/removeWithdrawal")
    @ApiOperation(value = "删除提现接口", notes = "删除提现接口")
    public ResponseEntity removeWithdrawal(long id){
        Withdrawal withdrawal = new Withdrawal();
        withdrawal.setId(id);
        withdrawal.setEnabled("0");
        withdrawalService.updateWithdrawal(withdrawal);
        ApiResult apiResult = new ApiResult();
        //return ResponseEntity.ok().build();
        return ResponseEntity.ok(apiResult);
    }

    /**
     * 修改提现接口
     */
    @PostMapping("/updateWithdrawal")
    @ApiOperation(value = "修改提现接口", notes = "修改提现接口")
    public ResponseEntity updateWithdrawal(@RequestBody Withdrawal withdrawal){
        withdrawalService.updateWithdrawal(withdrawal);
        ApiResult apiResult = new ApiResult();
        //return ResponseEntity.ok().build();
        return ResponseEntity.ok(apiResult);
    }
    
	/**
     * 分页获取提现接口
     */
    @RequestMapping("/getPaginationWithdrawal")
    @ApiOperation(value = "分页获取提现接口", notes = "分页获取提现接口")
    public ResponseEntity <ApiResult> getPaginationWithdrawal(long size, long current) {
        Map m = new HashMap<String, Object>();
        m.put("size", size);
        m.put("current", current);
        Page<Map<String, Object>> page = withdrawalService.getPaginationWithdrawal(m);
        //return ResponseEntity.ok(page);
        ApiResult apiResult = new ApiResult();
        apiResult.setData(page);
        return ResponseEntity.ok(apiResult);
    }
}